package com.sinosoft.sinopay.service.paytrade.biz.service.PaymentBatchTrans;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

//生成报文
public class CreateReport {
    //文件必须与此程序同一目录下
    private static final String FILE_NAME="report.txt";
    public static void main(String[] args) {
        
        try {
          //打印生成的属性
            print();
        } catch (Exception e) {
            System.out.println("出异常了，异常信息如下：");
            
            e.printStackTrace();
        }
    }
    
    public static void print() throws Exception{
      
        InputStream inputStream =CreateReport.class.getResourceAsStream(FILE_NAME);
        
        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream,"utf-8"));
        
        StringBuffer sb = new StringBuffer();
        String line = null;
        while((line=br.readLine())!=null){
            
            String[] content = line.split("<span title=");
            if(content.length==2){
                //生成属性
                String n1=content[1];
                n1=getLate(n1);
                sb.append(n1).append("\n");
            }
            
        }
        
        System.out.println(sb.toString());
    }
    
    
    private static String getLate(String str){
        if(str==null || str.trim().equals("")){
            return str;
        }
        String[] temp = str.split("/");
        if(temp.length==2){
            
            return temp[1];
        }else{
            return str;
        }
    } 
    //################################## 以下代码工具类仅供参考############################
    /**
     * 
     * 根据文件名读取文件内容。文件与此java程序同一目录下。
     * @param path 文件名称
     * @param charset 编码，例如utf-8
     * @return
     */
    public static String readFile(String path,String charset){
        StringBuffer sb = new StringBuffer();
        
        try {
            InputStream inputStream = CreateReport.class.getResourceAsStream(path);
            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream,charset));
            String line = null;
            while((line=br.readLine())!=null){
                sb.append(line).append("\r\n");
            }
            
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return sb.toString();
    }
    /**
     * 
     * 根据文件名读取文件内容。文件与此java程序同一目录下，使用utf-8编码
     * @param path 文件名称
     * @return
     */
    public static String readFile(String path){
        return readFile(path,"utf-8");
    }
}
